[% setvar title smart container slicing %]
<div id="archive-notice">
    <h3>This file is part of the Perl 6 Archive</h3>
    <p>To see what is currently happening visit <a href="http://www.perl6.org/">http://www.perl6.org/</a></p>
</div>
<div class='pod'>
<a name='TITLE'></a><h1>TITLE</h1>
<p>smart container slicing</p>
<a name='VERSION'></a><h1>VERSION</h1>
<pre>  Maintainer: David Nicol &lt;<a href='mailto:perl6rfc@davidnicol.com'>perl6rfc@davidnicol.com</a>&gt;
  Date: 1 Sep 2000
  Mailing List: <a href='mailto:perl6-language-data@perl.org'>perl6-language-data@perl.org</a>
  Number: 191
  Version: 1
  Status: Developing</pre>
<a name='ABSTRACT'></a><h1>ABSTRACT</h1>
<p>a more concise syntax for matching all the elements in a container that
are stored under keys that meet a condition</p>
<a name='DESCRIPTION'></a><h1>DESCRIPTION</h1>
<p>What if, instead of requiring</p>
<pre>	@onesIwant = @hash{grep /restriction on keys/ keys %hash};</pre>
<p>one could simply write</p>
<pre>	@onesIwant = @hash{/restriction on keys/};</pre>
<p>to obtain a list of all items stored in <code>hash</code> under keys containing
the string <code>'restriction on keys'</code></p>
<a name='IMPLEMENTATION'></a><h1>IMPLEMENTATION</h1>
<p>When interpreting the appearance of a single regex (including an object
resulting from a <code>qr//</code>) inside braces indicating container lookup,
in a &quot;slicing&quot; context, the regex is applied to the keys of the container
and the matching elements are returned, as per the longer syntax involving
an intermediate anonymous array.</p>
<a name='CONFLICTS'></a><h1>CONFLICTS</h1>
<p>In situations where one wants to pull a list of one item
out of a hash in which that item is keyed with a regex, assuming such
is possible, one will need to use</p>
<pre>	@listofoneitem = ( $hash{$regex} );</pre>
<p>instead of the syntax appropriated by this suggestion.</p>
<a name='BUT WAIT THERE'S MORE'></a><h1>BUT WAIT THERE'S MORE</h1>
<p>With the addition to the language of regular expression syntax to
deal numbers by value rather than is done now, the syntax described
in this document may provide a concise way to slice multidimensional
containers.</p>
<a name='REFERENCES'></a><h1>REFERENCES</h1>
</div>
